<template>
  <el-dialog v-bind="$attrs" v-model="visible"  :title="dialogtitle" width="30%" :before-close="handleClose">
    <el-form :model="form" ref="ruleFormRef" :disabled="islook" :rules="rules1" status-icon>
      <slot name="form" :form="form"></slot>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button v-if="!islook" @click="dialogVisible = false">取消</el-button>
        <el-button v-if="islook" plain type="primary" @click="print()"
          ><el-icon><Printer /></el-icon>打印</el-button
        >
        <el-button v-if="!islook" type="primary" @click="save()">保存</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script>
import { ElMessage } from 'element-plus'
import { httpGet, httpPost, httpPut, httpDel } from '/@/utils/request'
export default {
  emit: ['update:visible'],
  props: {
    islook: {
      type: Boolean,
      default: false, //展示序号标识
    },
    visible: {
      type: Boolean,
      default: false,
    },
    diaForm: {
      type: Object,
    },
    url: {
      type: Object,
      default: () => {},
    },
    rules: {
      type: Object,
    },
  },
  data() {
    return {
      rules1: {},
      form: {},
    }
  },
  watch: {
    rules: {
      handler(newValue) {
        this.rules1 = newValue
      },
      immediate: true,
    },
    diaForm: {
      handler(newValue) {
        this.form = newValue
      },
      immediate: true,
    },
  },
  methods: {
    save() {
      console.log(this.$parent.getList(), '父组件')
      console.log(this.form)
      this.dialogVisible = false
      this.$emit('update:visible', false)
      this.$parent.getList()

      // this.$refs['ruleFormRef'].validate(async valid => {
      //   if (valid) {
      //     if (this.form.id) {
      //       console.log(this.form)
      //       const { code } = await httpPut(this.url.editUrl, this.form)
      //       if (code == 200) {
      //         ElMessage.success('修改成功')
      //         this.dialogVisible = false
      //         this.$parent.getList()
      //       }
      //     } else {
      //       const { code } = await httpPost(this.url.addUrl, this.form)
      //       if (code == 200) {
      //         ElMessage.success('新增成功')
      //         this.dialogVisible = false
      //         this.$parent.getList()
      //       }
      //     }
      //   } else {
      //     console.log('error submit!!')
      //     return false
      //   }
      // })
    },
    print() {
      ElMessage.success('点击了打印')
    },
  },
}
</script>

<style>
</style>